package pers.zcr.meringue.monolithic.system.captcha.gatewayImpl.hutoolcaptcha;

import cn.hutool.captcha.AbstractCaptcha;
import cn.hutool.core.util.IdUtil;
import pers.zcr.meringue.monolithic.system.captcha.model.Captcha;

public abstract class CaptchaGenerator {
    final AbstractCaptcha captcha;
    //创建构造函数
    public CaptchaGenerator(AbstractCaptcha captcha) {
        this.captcha = captcha;
    }

    //生成验证码
    public Captcha generate() {
        captcha.createCode();

        String code = getCode();
        String img = captcha.getImageBase64();

        Captcha captcha = new Captcha();
        captcha.setCode(code);
        captcha.setImg(img);
        String uuid = IdUtil.simpleUUID();
        captcha.setUuid(uuid);
        return captcha;
    }

    abstract String getCode();

}
